if (Meteor.isServer) { 
  //实时库存
  Meteor.publish('inventory', function () {
    if(!this.userId) return;
    return Inventory.find({'company_id':Meteor.users.findOne(this.userId).company_id});
  });
}

Meteor.methods({
  switchStockLock:function(){
  },
  switchStockReduce:function(){
  },
  stockIn:function(){
  },
  stockTransfer:function(){
  },
  stockOut:function(){
  },
});

if (Inventory.find().count() === 0) {
  Inventory.insert({
    company_id:'1',
    qty:10,
    product_id:'1',
    brand:{name:'苹果',logo:'apple'},
    model:'iPhone 6 Plus (A1524)',
    min_sale_price:5000,
    sale_price:5600,
    distribution:[
      {
        qty:4,
        store_id:'3', store_name:'南山店', location:[-86.95444, 33.40178],
        warehouse_distribution:[
          {_id:'11',name:'柜组1', qty:2},
          {_id:'12', name:'柜组2', qty:2}
        ]
      }, {
        qty:6,
        store_id:'4', store_name:'福田店', location:[-86.95444, 33.40178],
        warehouse_distribution:[
          {_id:'15', name:'柜组1', qty:1},
          {_id:'16', name:'柜组2', qty:5}
        ]
      }
    ],
    islocked:false
  });

  Inventory.insert({
    company_id:'1',
    qty:12,
    product_id:'2',
    brand:{name:'小米',logo:'xiaomi'},
    model:'小米5 高配版',
    min_sale_price:2000,
    sale_price:2500,
    distribution:[
      {
        qty:6,
        store_id:'3', store_name:'南山店', location:[-86.95444, 33.40178],
        warehouse_distribution:[
          {_id:'11', name:'柜组1', qty:6}
        ]
      }, {
        qty:6,
        store_id:'4', store_name:'福田店', location:[-86.95444, 33.40178],
        warehouse_distribution:[
          {_id:'15', name:'柜组1', qty:1},
          {_id:'16', name:'柜组2', qty:5}
        ]
      }
    ],
    islocked:false
  });


  Inventory.insert({
    company_id:'1',
    qty:1,
    product_id:'4',
    brand:{name:'华为',logo:'huawei'},
    model:'荣耀8(R1530)',
    min_sale_price:2800,
    sale_price:3200,
    distribution:[
      {
        qty:1,
        store_id:'3', store_name:'南山店', location:[-86.95444, 33.40178],
        warehouse_distribution:[
          {_id:'11', name:'柜组1', qty:1}
        ]
      }
    ],
    islocked:true
  });

}
